package ym.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ym.mapper.ParenteralNutritionPlanMapper;
import ym.pojo.ParenteralNutritionPlan;
import ym.service.ParenteralNutritionPlanService;

import java.util.List;

@DubboService
public class ParenteralNutritionPlanServiceImpl implements ParenteralNutritionPlanService {

    @Autowired
    private ParenteralNutritionPlanMapper parenteralNutritionPlanMapper;

    @Override
    public void add(ParenteralNutritionPlan parenteralNutritionPlan) {
        parenteralNutritionPlanMapper.insert(parenteralNutritionPlan);
    }

    @Override
    public void update(ParenteralNutritionPlan parenteralNutritionPlan) {
        parenteralNutritionPlanMapper.updateById(parenteralNutritionPlan);
    }

    @Override
    public void delete(Integer id) {
        parenteralNutritionPlanMapper.deleteById(id);
    }

    @Override
    public void deleteByNutritionPlanId(Integer nutritionPlanId) {
        QueryWrapper<ParenteralNutritionPlan> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("nutritionPlanId", nutritionPlanId);
        parenteralNutritionPlanMapper.delete(queryWrapper);
    }

    @Override
    public ParenteralNutritionPlan findById(Integer id) {
        return parenteralNutritionPlanMapper.selectById(id);
    }

    @Override
    public List<ParenteralNutritionPlan> findAll() {
        return parenteralNutritionPlanMapper.selectList(null);
    }

    @Override
    public Page<ParenteralNutritionPlan> search(String search, int page, int size) {
        QueryWrapper<ParenteralNutritionPlan> queryWrapper = new QueryWrapper<>();
        if (search != null) {

        }
        return parenteralNutritionPlanMapper.selectPage(new Page(page, size), queryWrapper);
    }

    @Override
    public Page<ParenteralNutritionPlan> searchByNutritionPlanId(Integer nutritionPlanId, String search, int page, int size) {
        QueryWrapper<ParenteralNutritionPlan> queryWrapper = new QueryWrapper<>();
        if (search != null) {
            queryWrapper.eq("nutritionPlanId", nutritionPlanId);
        } else {
            queryWrapper.eq("nutritionPlanId", nutritionPlanId);
        }
        return parenteralNutritionPlanMapper.selectPage(new Page(page, size), queryWrapper);
    }


}
